<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <script src="./adaptive.js"></script>
    <title>稳如哈马比，注册下载APP</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <link
      id="mobile-style"
      media="only screen and (max-width: 767px)"
      type="text/css"
      rel="stylesheet"
      href="./wx/wx.css"
    />
    <style type="text/css">
      * {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
      }
      .register-page {
        position: relative;
        width: 100vw;
        min-height: 100vh;
        background: linear-gradient(to bottom, #360f18, #3b0001);
        overflow-x: hidden;
      }
      .top {
        position: absolute;
        top: 0;
        left: 0;
        width: 7.5rem;
        height: 1.3rem;
        background: url("./images/top.png") no-repeat;
        background-size: contain;
      }
      .page-bg {
        position: relative;
        width: 7.5rem;
        height: 11rem;
        background: url("./images/bg.png") no-repeat;
        background-size: contain;
      }
      .page-bg .title {
        position: absolute;
        width: 7.02rem;
        height: 0.82rem;
        top: 0.3rem;
        left: 50%;
        transform: translateX(-50%);
        background: url("./images/title.png") no-repeat;
        background-size: contain;
      }
      .content-wrapper {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 7.5rem;
        height: 6.8rem;
        background: url("./images/football_bg.png") no-repeat;
        background-size: contain;
      }
      .content-wrapper .red-packet {
        position: absolute;
        top: -1.08rem;
        left: 51%;
        transform: translateX(-50%);
        width: 4.69rem;
        height: 2.72rem;
        background: url("./images/red1.png") no-repeat;
        background-size: contain;
      }
      .input-wrapper {
        position: absolute;
        top: 2.6rem;
        left: 51%;
        transform: translateX(-50%);
        width: 5.95rem;
        height: 0.94rem;
        background: #ffffff;
        border-radius: 30px;
      }
      .input-wrapper input {
        width: 100%;
        height: 100%;
        border-radius: 30px;
        outline: none;
        border: none;
        padding-left: 15px;
        font-size: 15px;
      }
      .input-wrapper .input-short {
        width: 3.8rem;
        height: 100%;
        border-radius: 30px;
        outline: none;
        border: none;
        padding-left: 15px;
        font-size: 15px;
      }
      .input-wrapper input::placeholder {
        font-size: 13px;
        color: #a5a5a5;
      }
      .verify-code-input {
        top: 3.6rem;
      }
      .verify-code-input .prompt-text {
        position: absolute;
        top: 0.2rem;
        right: 0.5rem;
        color: #3a63c5;
        font-size: 13px;
        width: 1.8rem;
        white-space: nowrap;
        text-align: right;
      }
      .sign-code-input {
        top: 4.6rem;
      }
      .sign-code-input .prompt-text {
        position: absolute;
        right: 0.5rem;
        top: 0.3rem;
        color: #3a63c5;
        font-size: 13px;
        width: 1.8rem;
        white-space: nowrap;
        text-align: right;
      }
      #J-imgbtn {
        height: 0.5rem;
        width: 1.2rem;
      }
      .register-btn {
        position: absolute;
        width: 6.2rem;
        height: 0.96rem;
        background: url("./images/register_btn.png") no-repeat;
        background-size: contain;
        top: 5.7rem;
        left: 51%;
        transform: translateX(-50%);
      }
      body > a {
        display: none;
      }
    </style>
  </head>
  <body>
    <script>
      window["adaptive"].designWidth = 750;
      window["adaptive"].baseFont = 24;
      window["adaptive"].scaleType = 1;
      // 初始化
      window.adaptive.init();
    </script>
    <div class="register-page">
      <div class="page-bg"></div>
      <div class="content-wrapper">
        <div class="red-packet"></div>
        <div class="phone-input input-wrapper">
          <input
            type="number"
            placeholder="请输入注册手机号"
            id="phone-num"
            maxlength="11"
          />
        </div>
        <div class="verify-code-input input-wrapper">
          <input
            id="J-imgcode"
            class="input-short"
            type="text"
            placeholder="请输入图片验证码"
          />
          <div class="prompt-text">
            <img
              id="J-imgbtn"
              src="http://39.98.47.61:18882/validate/getImageCode"
            />
          </div>
        </div>
        <div class="sign-code-input input-wrapper">
          <input type="text" placeholder="请输入短信验证码" id="verify-num" />
          <div class="prompt-text" id="J-verbtn">获取短信验证码</div>
        </div>
        <div class="register-btn"></div>
      </div>
    </div>

    <div id="weixin-tip-wrapper">
      <div id="weixin-tip-box">
        <div class="triangle_border_up">
          <span></span>
        </div>
        <div class="weixin-tip">
          <p>
            请点击右上角
          </p>
          <p class="content">
            选择"浏览器中打开"
          </p>
        </div>
      </div>
    </div>
    <script>
      function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split("=");
          if (pair[0] == variable) {
            return pair[1];
          }
        }
        return false;
      }
      var isRightPhone;
      var phoneNum;
      var verifyCode;
      var imgCode = "";
      var canClick = true; // 获取验证码按钮是否能点击
      var domain = "http://39.98.47.61:18882";
      var inviterId = getQueryVariable("user_id");
      var channel = "h5";
      if (inviterId > 0) {
        channel = "invite";
      }
      var commonParams = {
        appKey: "LOVE-LOTTERY",
        channel: channel,
        source: 3,
      };
      document.getElementById("phone-num").onchange = function (e) {
        const preg = /^1(3|5|6|7|8|9)(\d){9}$/;
        phoneNum = e.target.value;
        isRightPhone = preg.test(phoneNum);
        if (!isRightPhone) {
          jAlert("请输入正确手机号");
        }
      };
      var resetVercode = function () {
        $("#J-imgbtn").attr(
          "src",
          "http://39.98.47.61:18882/validate/getImageCode?=a" + Math.random()
        );
      };
      document.getElementById("verify-num").onchange = function (e) {
        verifyCode = e.target.value;
      };
      document.getElementById("J-imgcode").onchange = function (e) {
        imgCode = e.target.value;
      };
      $("#J-imgbtn")[0].onclick = function () {
        resetVercode();
      };
      // 点击获取验证码
      $("#J-verbtn")[0].onclick = function () {
        if (!canClick) {
          return;
        }
        if (!isRightPhone) {
          jAlert("请输入正确手机号");
          return;
        }
        if (imgCode.length == 0) {
          resetVercode();
          jAlert("请输入图片验证码");
          return;
        }
        if (imgCode.length != 5) {
          resetVercode();
          jAlert("请输入正确的图片验证码");
          return;
        }
        let data = Object.assign(commonParams, {
          mobile: phoneNum,
          codeType: 0,
          imgCode: imgCode,
        });
        $.post(domain + "/sms/h5SendVerifyCode", data, function (res) {
          console.log(res);
          
          if (res.code === 0) {
            jAlert("验证码请求成功");
            resetVerifyBtn();
          } else if (res.msg == "该手机号已经注册！") {
            window.location = "download.html";
          } else {
            resetVercode();
            jAlert(data.msg);
          }
        });
        function resetVerifyBtn() {
          $("#J-verbtn")[0].innerHTML = "60s";
          canClick = false;
          let timeCount = 60;
          var timer = setInterval(function () {
            timeCount--;
            $("#J-verbtn")[0].innerHTML = timeCount + "s";
            if (timeCount <= 0) {
              clearInterval(timer);
              $("#J-verbtn")[0].innerHTML = "获取短信验证码";
              canClick = true;
            }
          }, 1000);
        }
      };
      // 点击注册按钮
      $(".register-btn")[0].onclick = function () {
        if (
          !isRightPhone ||
          verifyCode.length == 0 ||
          imgCode.length == 0 ||
          imgCode.length != 5
        ) {
          jAlert("请输入注册信息");
          return;
        }
        var data = Object.assign(commonParams, {
          mobile: phoneNum,
          verifyCode: verifyCode,
          inviterId: inviterId,
        });
        $.post(domain + "/login/loginRegister", data, function (res) {
          if (res.code === 0 || res.code == 100006) {
            window.location.href = "download.html";
          } else {
            jAlert(res.msg);
          }
        });
        clearInterval(timer);
      };
    </script>

    <SCRIPT src="./jquery.ui.draggable.js" type=text/javascript></SCRIPT>
    <SCRIPT src="./jquery.alerts.js" type=text/javascript></SCRIPT>
    <LINK media=screen href="./jquery.alerts.css" type=text/css rel=stylesheet>
    <script type="text/javascript" src="https://s4.cnzz.com/z_stat.php?id=1278260129&web_id=1278260129"></script>

    <SCRIPT src="./wx.js?m=111" type=text/javascript></SCRIPT>
  </body>
</html>
